package hello.dao;

import java.util.List;
import java.util.Map;

import hello.bean.fileds.Fileds;
import hello.bean.person.Person;
import hello.bean.person.PersonAndAddress;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;

@RepositoryRestResource(collectionResourceRel = "person", path = "person")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {


    List<Person> findByLastName(@Param("name") String name);


    @RestResource(path = "getPersonAndAddress", rel = "getPersonAndAddress")
    @Query(value = "select p.first_name  from person p,address a where p.id=a.id and a.id=:id", nativeQuery = true)
    List<Object[]> getPersonAndAddress(@Param("id") Long id);

}
